<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<%@include file="includeHead.jsp"%>

</head>
<body>
	<table id="main_form" class="easyui-datagrid" title="用户列表"
		data-options="pagination:true,rownumbers:true,singleSelect:true,url:'${pageContext.request.contextPath}/GetUserList',method:'get',toolbar:toolbarTop">
		<thead>
			<tr>
				<th data-options="field:'usId',width:80">用户编号</th>
				<th data-options="field:'userName',width:100">用户名</th>
				<th data-options="field:'uiNice',width:100">昵称</th>
				<th data-options="field:'uiEmail',width:80,align:'right'">邮箱</th>
				<th data-options="field:'uiNote',width:80,align:'right'">个人说明</th>
			</tr>
		</thead>
	</table>

	<div id="addUserDiv" class="easyui-window" title="添加用户"
		data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false"
		style="width: 300px; height: 400px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="addForm" method="post">
					<table cellpadding="5">
						<tr id="tr_password">
							<td>密码:</td>
							<td><input type="password" id="form_password"
								name="password" data-options="required:true,validType:'email'" style="width:100px;"></input>
								</td>
						</tr>
						<tr>
							<td>用户昵称:</td>
							<td><input type="text" id="form_userNice" name="userNice"
								data-options="required:true"></input></td>
						</tr>
						<tr>
							<td>用户邮箱:</td>
							<td><input name="userEmail" id="form_userEmail"
								data-options="multiline:false"></input></td>
						</tr>
						<tr>
							<td>个人说明:</td>
							<td><input name="userNote" id="form_userNote"
								data-options="multiline:true" style="height: 60px"></input></td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
					href="javascript:void(0)" onclick="" id="btn_Submit"
					style="width: 80px">确认</a> <a class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
					onclick="$('#addUserDiv').window('close');" style="width: 80px">取消</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		var toolbarTop = [
				{
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						$('#addUserDiv').form('clear');
						$("#addUserDiv").panel({
							title : "添加用户"
						});
						$('#btn_Submit').attr("onclick", " cmd('add');")
						$('#addUserDiv').window('open');
					}
				},
				{
					text : '修改',
					iconCls : 'icon-cut',
					handler : function() {
						$('#addUserDiv').form('clear');
						var row = $('#main_form').datagrid('getSelected');

						if (row != null) {
							$("#form_userName").val(row.userName);
							$("#form_userNice").val(row.uiNice);
							$("#form_userEmail").val(row.uiEmail);
							$("#form_userNote").val(row.uiNote);
							//$("#form_password").val(row.)
							$("#addUserDiv").panel({
								title : "修改用户"
							});
							$('#btn_Submit').attr("onclick", " cmd('modify');")
							$('#addUserDiv').window('open');

						} else
							alert('请选择要修改的用户');

					}
				},
				'-',
				{
					text : '删除',
					iconCls : 'icon-save',
					handler : function() {
						var row = $('#main_form').datagrid('getSelected');

						if (row != null) {
							$
									.post(
											"${pageContext.request.contextPath }/AdminUserControlServlet?control=deleteUser&usId="
													+ row.usId, null, function(
													result) {
												if (result != 'success') {
													alert(result);
												} else {
													alert("删除成功");
													closeForm();
													$('#main_form').datagrid('reload');
												}
											}, "text");
						} else
							alert('请选择要删除的用户');
					}
				} ];
		function cmd(c) {
			if (c == "add") {
				addUserFun();
			}
			if (c == "modify") {
				modifyUserFun();
			}

		}
		function modifyUserFun() {
			var d = $("#addForm").serialize();
			d = d + "&usId=" + $('#main_form').datagrid('getSelected').usId;
			$
					.post(
							"${pageContext.request.contextPath }/AdminUserControlServlet?control=modify",
							d, function(result) {
								if (result != 'success') {
									alert(result);
								} else {
									alert("修改成功");
									closeForm();
									$('#main_form').datagrid('reload');
									$('#addUserDiv').form('clear');
								}
							}, "text");
		}
		function addUserFun() {
			var d = $("#addForm").serialize();
			$
					.post(
							"${pageContext.request.contextPath }/AdminUserControlServlet?control=addUser",
							d, function(result) {
								if (result != 'success') {
									alert(result);
								} else {
									alert("添加成功");
									
									closeForm();
									$('#main_form').datagrid('reload');
								}
							}, "text");
		}
		function closeForm() {
			$('#addUserDiv').window('close');
		}
	</script>

</body>
</html>